package com.sx.medicinecard.controller;


import com.google.protobuf.ServiceException;
import com.sx.medicinecard.common.ResponseResult;
import com.sx.medicinecard.entity.dto.BrushOrderDto;
import com.sx.medicinecard.entity.dto.SxOrderInfoDto;
import com.sx.medicinecard.service.SxOrderInfoBrushService;
import com.sx.medicinecard.service.SxUserLoginService;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 刷单订单表(SxOrderInfoBrush)控制层
 *
 * @author makejava
 * @since 2024-07-17 18:28:57
 */
@RestController
@RequestMapping("/sxOrderInfoBrush")
public class SxOrderInfoBrushController {
    /**
     * 服务对象
     */
    @Resource
    private SxOrderInfoBrushService sxOrderInfoBrushService;

    @Resource
    private SxUserLoginService sxUserLoginService;

    /**
     * 分页查询订单信息列表(刷单)
     * @param brushOrderDto
     * @return
     */
    @PostMapping("/getOrderListByPage")
    @ApiOperation("分页查询订单信息列表")
    public ResponseResult selectPage(@RequestBody BrushOrderDto brushOrderDto,HttpServletRequest httpServletRequest) throws IOException, ServiceException {
        String loginChannelCode = sxUserLoginService.getUserLogin(httpServletRequest).getChannelCode();
        if(StringUtils.isNoneBlank(loginChannelCode)&&!"admin".equals(loginChannelCode)){
            brushOrderDto.setLoginChannelCode(loginChannelCode);
        }
        return sxOrderInfoBrushService.getOrderListByPage(brushOrderDto);
    }


    /**
     * 订单导出excel(刷单)
     * @param request
     * @param response
     */
    @PostMapping("/exportToExcel")
    @ApiOperation("订单导出excel")
    public void exportToExcel(@RequestBody BrushOrderDto brushOrderDto, HttpServletRequest request, HttpServletResponse response) throws ServiceException {
        String loginChannelCode = sxUserLoginService.getUserLogin(request).getChannelCode();
        if(StringUtils.isNoneBlank(loginChannelCode)&&!"admin".equals(loginChannelCode)){
            brushOrderDto.setLoginChannelCode(loginChannelCode);
        }
        sxOrderInfoBrushService.exportToExcel(brushOrderDto,request,response);
    }
}

